package com.cq.hd.admin.controller;

import com.cq.hd.admin.annotation.RequiresPermissionsDesc;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.utils.StringUtils;
import com.cq.hd.member.api.TbBusinessRechargeApplyApi;
import com.cq.hd.member.api.dto.BusinessRechargeApplyAuditDto;
import com.cq.hd.member.api.dto.BusinessRechargeApplyPageDto;
import com.cq.hd.member.api.vo.BusinessRechargeApplyPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "商家补贴充值(线下)申请相关接口")
@Slf4j
@RestController
@RequestMapping("/businessRechargeApply")
public class TbBusinessRechargeApplyController extends BaseController {

    @Autowired
    private TbBusinessRechargeApplyApi businessRechargeApplyApi;

    @ApiOperation(value = "申请列表")
    @RequiresPermissions("business:rechargeApply:page")
    @RequiresPermissionsDesc(menu = {"商家", "补贴充值"}, button = "查询")
    @GetMapping("/page")
    public Result<Page<BusinessRechargeApplyPageVo>> page(BusinessRechargeApplyPageDto businessRechargeApplyPageDto) {
        // keyword 商家id/商家简称 搜索
        String keyword = businessRechargeApplyPageDto.getKeyword();
        if (StringUtils.isBusinessNo(keyword)) {
            businessRechargeApplyPageDto.setBusinessNo(keyword);
        } else if (StringUtils.isNotBlank(keyword)) {
            businessRechargeApplyPageDto.setBusinessShortName(keyword);
        }
        return businessRechargeApplyApi.page(businessRechargeApplyPageDto);
    }

    @ApiOperation(value = "商家线下充值审核")
    @RequiresPermissions("business:rechargeApply:audit")
    @RequiresPermissionsDesc(menu = {"财务管理", "商家线下充值审核"}, button = "审核")
    @PostMapping("/audit")
    public Result<Boolean> audit(@RequestBody BusinessRechargeApplyAuditDto businessRechargeApplyAuditDto) {
        return businessRechargeApplyApi.audit(businessRechargeApplyAuditDto);
    }
}
